﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Recipe
{
    public class RecipieSteps:IRecipeSteps
    {
        public void AddStepsToRecipe(int recipeId, int stepCount, string text, Model.RecipeImage recipeImage, ref Model.NutriLeafDBEntities context)
        {
            Model.RecipeStep st = new Model.RecipeStep();
            st.RecipeID = recipeId;
            st.StepCount = stepCount;
            st.Text = text;
            st.RecipeImage = recipeImage;
            context.RecipeSteps.AddObject(st);
            context.SaveChanges();
            
        }

        public void AddStepsToRecipe(Model.RecipeStep step, ref Model.NutriLeafDBEntities context)
        {
            context.RecipeSteps.AddObject(step);
            context.SaveChanges();
        }

        public void RemoveStepsFromRecipe(int recipeStepId, ref Model.NutriLeafDBEntities context)
        {
            context.DeleteObject(context.RecipeSteps.Where(p => p.RecipeStepID == recipeStepId).First());
            context.SaveChanges();
        }

        public void UpdateRecipeSteps(Model.RecipeStep step, ref Model.NutriLeafDBEntities context)
        {
            Model.RecipeStep s = context.RecipeSteps.Where(p => p.RecipeStepID == step.RecipeStepID).First();
            s = step;
            context.SaveChanges();
        }

        public List<Model.RecipeStep> GetAllRecipeSteps(int recipeId, ref Model.NutriLeafDBEntities context)
        {
            return context.RecipeSteps.Where(p => p.RecipeID == recipeId).ToList();
        }

        public Model.RecipeStep GetRecipeStep(int recipeStepId, ref Model.NutriLeafDBEntities context)
        {
            return context.RecipeSteps.Where(p => p.RecipeStepID == recipeStepId).First();
        }
    }
}